/*
 * Location.java
 * Copyright (C) 12/24/2005, 20:52 Francisco J. Hernández
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Library General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Library General Public License for more details.
 *
 * You should have received a copy of the GNU Library General Public
 * License along with this library; if not, write to the Free
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 * 
 */

package Sindarin.Common;
import java.util.StringTokenizer;


/**
 *
 * @author Francisco J. Hernández
 */
public class Location {
    public int x;
    public int y;

    /** Creates a new instance of Location */
    public Location() {
    }

    public Location(int x, int y) {
        setCoor(x, y);
    }

    public Location(String cad) {
        StringTokenizer str = new StringTokenizer(cad,"[ ,]\n\t\r");
	x = (new Integer(str.nextToken()).intValue());
	y = (new Integer(str.nextToken()).intValue());
    }
    
    public void setCoor(int x, int y) {
        this.x = x;
        this.y = y;        
    }
    
    public boolean equals(Location b) {
        return ((x == b.x) && (y == b.y));
    }
    
    public Location add(Location b) {
        return new Location(x+b.x, y+b.y);
    }
    
    public Location sub(Location b) {
        return new Location(x-b.x, y-b.y);
    }
    
    public String toString() {
        return "[x, y] = [" + x + ", " + y + "]";
    }
}
